package com.myk.game.gobangchess.rooms.absrooms;

import com.myk.game.gobangchess.Player;
import com.myk.game.gobangchess.Room;
import com.myk.game.gobangchess.constants.Msger;

/**
 * 仅单人模式房间
 */
public abstract class AbsPersonalRoom extends Room {
    public AbsPersonalRoom(String roomName, String roomIntroduce, String chessName, int[][] curGrids, boolean isSupportPersonal, boolean isSaveHistoryToFile,String ... modes) {
        super(roomName, roomIntroduce, chessName, curGrids, true, isSaveHistoryToFile,modes);
    }

    @Override
    public boolean isSupportPersonal() {
        return true;
    }

    @Override
    public void setBlackPlayer(Player player) {
        if (player_white != null && player_white != player) {
            player.sendMessage(Msger.broadcast, "仅单人游戏，您不能落座。");
            return;
        }
        super.setBlackPlayer(player);
        if (player_white == null) {
            setWhitePlayer(player); //自动落座
        }
    }

    @Override
    public void setWhitePlayer(Player player) {
        if (player_black != null && player_black != player) {
            player.sendMessage(Msger.broadcast, "仅单人游戏，您不能落座。");
            return;
        }
        super.setWhitePlayer(player);
        if (player_black == null) {
            setBlackPlayer(player); //自动落座
        }
    }

    @Override
    public void playerEnter(Player player) {
        super.playerEnter(player);
        if (player == player_black || player == player_white){
            removeSpectator(player);
            if (overFlag == 2){
                dispatchContinueButton();
            }
        }
    }

    @Override
    public void playerLeaveRoom(Player player) {
        if (this.player_black == player && this.player_white == player){
            return;
        }
        super.playerLeaveRoom(player);
    }

    @Override
    public void checkGameStart() {
        if (player_black != null && player_white != null && player_black == player_white) {
            if (step == 0) {
                doStart(); //对弈正式开始
            }
            else { //判断当前应该谁走并执行通知
                noticeCurMove();
            }
        }
    }

}
